﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class TradePartnerDA : ITradePartnerDA
    {
        private string ADDRESS = "@ADDRESS";
        private string B_ADDRESS = "@B_ADDRESS";
        private string B_CITY = "@B_CITY";
        private string B_CONTACT1 = "@B_CONTACT1";
        private string B_CONTACT2 = "@B_CONTACT2";
        private string B_COUNTRY = "@B_COUNTRY";
        private string B_COUNTRY_CODE = "@B_COUNTRY_CODE";
        private string B_EMAIL1 = "@B_EMAIL1";
        private string B_EMAIL2 = "@B_EMAIL2";
        private string B_FAX1 = "@B_FAX1";
        private string B_FAX2 = "@B_FAX2";
        private string B_PHONE1 = "@B_PHONE1";
        private string B_PHONE2 = "@B_PHONE2";
        private string B_STATE = "@B_STATE";
        private string B_ZIP = "@B_ZIP";
        private string CHECK_THE_WEIGHT_DIFFERENCE = "@CHECK_THE_WEIGHT_DIFFERENCE";
        private string CITY = "@CITY";
        private string COMPANY = "@COMPANY";
        private string CONTACT1 = "@CONTACT1";
        private string CONTACT2 = "@CONTACT2";
        private string COUNTRY = "@COUNTRY";
        private string CREATED_BY = "@CREATED_BY";
        private string DESCRIPTION = "@DESCRIPTION";
        private string DIFFERENCES_IN_APPROACH = "@DIFFERENCES_IN_APPROACH";
        private string EMAIL1 = "@EMAIL1";
        private string EMAIL2 = "@EMAIL2";
        private string FAX1 = "@FAX1";
        private string FAX2 = "@FAX2";
        private string FINANCE_LOGISTICAL_CALC_BY = "@FINANCE_LOGISTICAL_CALC_BY";
        private string FINANCE_LOGISTICAL_CTRL = "@FINANCE_LOGISTICAL_CTRL";
        private string IS_ACTIVE = "@IS_ACTIVE";
        private string IS_REQUIRED_EXTERNAL_ID = "@IS_REQUIRED_EXTERNAL_ID";
        private string OWNER_ID = "@OWNER_ID";
        private string PERCENTAGE_WEIGHT_DIFFERENCE = "@PERCENTAGE_WEIGHT_DIFFERENCE";
        private string PHONE1 = "@PHONE1";
        private string PHONE2 = "@PHONE2";
        private string REMARK = "@REMARK";
        private string SQL_CHECK_OWNER_ID_UNIQUE = " SELECT COUNT(1) FROM @_@OWNER WHERE OWNER_ID = @OWNER_ID ";
        private string SQL_DELETE_OWNER = " DELETE FROM @_@OWNER WHERE OWNER_ID = @OWNER_ID ";
        private string SQL_INSERT_OWNER = " INSERT INTO @_@OWNER ( WH_ID, OWNER_ID, TYPE, COMPANY, DESCRIPTION, VAT, CITY, STATE, ZIP, COUNTRY, ADDRESS, CONTACT1, CONTACT2, PHONE1, PHONE2, FAX1, FAX2, EMAIL1, EMAIL2, B_CITY, B_STATE, B_ZIP, B_COUNTRY, B_COUNTRY_CODE, B_ADDRESS, B_CONTACT1, B_CONTACT2, B_PHONE1, B_PHONE2, B_FAX1, B_FAX2, B_EMAIL1, B_EMAIL2, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, REMARK, IS_ACTIVE, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE,IS_REQUIRED_EXTERNAL_ID, FINANCE_LOGISTICAL_CTRL, FINANCE_LOGISTICAL_CALC_BY,CHECK_THE_WEIGHT_DIFFERENCE,PERCENTAGE_WEIGHT_DIFFERENCE,DIFFERENCES_IN_APPROACH) VALUES ( @WH_ID, @OWNER_ID, @TYPE, @COMPANY, @DESCRIPTION, @VAT, @CITY, @STATE, @ZIP, @COUNTRY, @ADDRESS, @CONTACT1, @CONTACT2, @PHONE1, @PHONE2, @FAX1, @FAX2, @EMAIL1, @EMAIL2, @B_CITY, @B_STATE, @B_ZIP, @B_COUNTRY, @B_COUNTRY_CODE, @B_ADDRESS, @B_CONTACT1, @B_CONTACT2, @B_PHONE1, @B_PHONE2, @B_FAX1, @B_FAX2, @B_EMAIL1, @B_EMAIL2, @UDF1, @UDF2, @UDF3, @UDF4, @UDF5, @UDF6, @UDF7, @UDF8, @UDF9, @UDF10, @REMARK, @IS_ACTIVE, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE(),@IS_REQUIRED_EXTERNAL_ID, @FINANCE_LOGISTICAL_CTRL, @FINANCE_LOGISTICAL_CALC_BY,@CHECK_THE_WEIGHT_DIFFERENCE,@PERCENTAGE_WEIGHT_DIFFERENCE,@DIFFERENCES_IN_APPROACH)  ";
        private string SQL_SELECT_ALL_OWNER = " SELECT  OWNER.ROWID AS ROWID, OWNER.WH_ID AS WH_ID, OWNER.OWNER_ID AS OWNER_ID, OWNER.TYPE AS TYPE, OWNER.COMPANY AS COMPANY, OWNER.DESCRIPTION AS DESCRIPTION, OWNER.VAT AS VAT, OWNER.CREDIT_LIMIT AS CREDIT_LIMIT, OWNER.PO_ALPHA_PREFIX AS PO_ALPHA_PREFIX, OWNER.ASN_ALPHA_PREFIX AS ASN_ALPHA_PREFIX, OWNER.SO_ALPHA_PREFIX AS SO_ALPHA_PREFIX, OWNER.CITY AS CITY, OWNER.STATE AS STATE, OWNER.ZIP AS ZIP, OWNER.COUNTRY AS COUNTRY, OWNER.COUNTRY_CODE AS COUNTRY_CODE, OWNER.ADDRESS AS ADDRESS, OWNER.CONTACT1 AS CONTACT1, OWNER.CONTACT2 AS CONTACT2, OWNER.PHONE1 AS PHONE1, OWNER.PHONE2 AS PHONE2, OWNER.FAX1 AS FAX1, OWNER.FAX2 AS FAX2, OWNER.EMAIL1 AS EMAIL1, OWNER.EMAIL2 AS EMAIL2, OWNER.B_CITY AS B_CITY, OWNER.B_STATE AS B_STATE, OWNER.B_ZIP AS B_ZIP, OWNER.B_COUNTRY AS B_COUNTRY, OWNER.B_COUNTRY_CODE AS B_COUNTRY_CODE, OWNER.B_ADDRESS AS B_ADDRESS, OWNER.B_CONTACT1 AS B_CONTACT1, OWNER.B_CONTACT2 AS B_CONTACT2, OWNER.B_PHONE1 AS B_PHONE1, OWNER.B_PHONE2 AS B_PHONE2, OWNER.B_FAX1 AS B_FAX1, OWNER.B_FAX2 AS B_FAX2, OWNER.B_EMAIL1 AS B_EMAIL1, OWNER.B_EMAIL2 AS B_EMAIL2, OWNER.DEFAULT_CARTON_GROUP AS DEFAULT_CARTON_GROUP, OWNER.DEFAULT_PACK_ID AS DEFAULT_PACK_ID, OWNER.DEFAULT_LOT_TEMPLATE_ID AS DEFAULT_LOT_TEMPLATE_ID, OWNER.DEFAULT_PUTAWAY_RULE_ID AS DEFAULT_PUTAWAY_RULE_ID, OWNER.DEFAULT_PREALLOCATE_RULE_ID AS DEFAULT_PREALLOCATE_RULE_ID, OWNER.DEFAULT_ALLOCATE_RULE_ID AS DEFAULT_ALLOCATE_RULE_ID, OWNER.DEFAULT_ROTATION_RULE_ID AS DEFAULT_ROTATION_RULE_ID, OWNER.CALCULATE_PUTAWAY_LOCATION AS CALCULATE_PUTAWAY_LOCATION, OWNER.RECEIPT_VALIDATION_ID AS RECEIPT_VALIDATION_ID, OWNER.DEFAULT_QC_LOC AS DEFAULT_QC_LOC, OWNER.DEFAULT_QC_LOC_OUT AS DEFAULT_QC_LOC_OUT, OWNER.DEFAULT_RETURNS_LOC AS DEFAULT_RETURNS_LOC, OWNER.DEFAULT_PACKING_LOCATION AS DEFAULT_PACKING_LOCATION, OWNER.UDF1 AS UDF1, OWNER.UDF2 AS UDF2, OWNER.UDF3 AS UDF3, OWNER.UDF4 AS UDF4, OWNER.UDF5 AS UDF5, OWNER.UDF6 AS UDF6, OWNER.UDF7 AS UDF7, OWNER.UDF8 AS UDF8, OWNER.UDF9 AS UDF9, OWNER.UDF10 AS UDF10, OWNER.REMARK AS REMARK, OWNER.PACKING_VALIDATION_TEMPLATE AS PACKING_VALIDATION_TEMPLATE, OWNER.ENABLE_OPP_XDOCK AS ENABLE_OPP_XDOCK, OWNER.OPP_ORDER_STRATEGY_ID AS OPP_ORDER_STRATEGY_ID, OWNER.ALLOW_OVER_SHIPMENT AS ALLOW_OVER_SHIPMENT, OWNER.APPORTION_RULE AS APPORTION_RULE, OWNER.ORDER_DATE_START_DAYS AS ORDER_DATE_START_DAYS, OWNER.ORDER_DATE_END_DAYS AS ORDER_DATE_END_DAYS, OWNER.MAXIMUM_ORDERS AS MAXIMUM_ORDERS, OWNER.MINIMUM_PERCENT AS MINIMUM_PERCENT, OWNER.ORDER_TYPE_RESTRICT01 AS ORDER_TYPE_RESTRICT01, OWNER.ORDER_TYPE_RESTRICT02 AS ORDER_TYPE_RESTRICT02, OWNER.ORDER_TYPE_RESTRICT03 AS ORDER_TYPE_RESTRICT03, OWNER.ORDER_TYPE_RESTRICT04 AS ORDER_TYPE_RESTRICT04, OWNER.ORDER_TYPE_RESTRICT05 AS ORDER_TYPE_RESTRICT05, OWNER.ORDER_TYPE_RESTRICT06 AS ORDER_TYPE_RESTRICT06, OWNER.ENABLE_PACKING_DEFAULT AS ENABLE_PACKING_DEFAULT, OWNER.INSPECT_AT_PACK AS INSPECT_AT_PACK, OWNER.MULTI_ZONE_PL_PA AS MULTI_ZONE_PL_PA, OWNER.CREATE_PA_TASK_ON_RF_RECEIPT AS CREATE_PA_TASK_ON_RF_RECEIPT, OWNER.ORDER_BREAK_DEFAULT AS ORDER_BREAK_DEFAULT, OWNER.LPN_BARCODE_SYMBOLOGY AS LPN_BARCODE_SYMBOLOGY, OWNER.LPN_BARCODE_FORMAT AS LPN_BARCODE_FORMAT, OWNER.LPN_LENGTH AS LPN_LENGTH, OWNER.LPN_START_NUMBER AS LPN_START_NUMBER, OWNER.NEXT_LPN_NUMBER AS NEXT_LPN_NUMBER, OWNER.LPN_ROLLBACK_NUMBER AS LPN_ROLLBACK_NUMBER, OWNER.CASE_LABEL_TYPE AS CASE_LABEL_TYPE, OWNER.APPLICATION_ID AS APPLICATION_ID, OWNER.SSCC_1ST_DIGIT AS SSCC_1ST_DIGIT, OWNER.UCC_VENDOR_NUMBER AS UCC_VENDOR_NUMBER, OWNER.CC_DISCREPANCY_RULE AS CC_DISCREPANCY_RULE, OWNER.CC_ADJ_BY_RF AS CC_ADJ_BY_RF, OWNER.CC_SKU_LOC AS CC_SKU_LOC, OWNER.PI_SKU_LOC AS PI_SKU_LOC, OWNER.ALLOW_COMMINGLED_LPN AS ALLOW_COMMINGLED_LPN, OWNER.ALLOW_AUTO_CLOSE_FOR_ASN AS ALLOW_AUTO_CLOSE_FOR_ASN, OWNER.ALLOW_AUTO_CLOSE_FOR_PO AS ALLOW_AUTO_CLOSE_FOR_PO, OWNER.ALLOW_SYSTEM_GENERATED_LPN AS ALLOW_SYSTEM_GENERATED_LPN, OWNER.ALLOW_SINGLE_SCANRECEIVING AS ALLOW_SINGLE_SCANRECEIVING, OWNER.BARCODE_CONFIG_ID AS BARCODE_CONFIG_ID, OWNER.TRACK_INVENTORY_BY AS TRACK_INVENTORY_BY, OWNER.DUP_CASE_ID AS DUP_CASE_ID, OWNER.SKU_SETUP_REQUIRED AS SKU_SETUP_REQUIRED, OWNER.IS_ACTIVE AS IS_ACTIVE, OWNER.TS AS TS, OWNER.CREATED_BY AS CREATED_BY, OWNER.CREATED_DATE AS CREATED_DATE, OWNER.UPDATED_BY AS UPDATED_BY, OWNER.UPDATED_DATE AS UPDATED_DATE,OWNER.IS_REQUIRED_EXTERNAL_ID,OWNER.FINANCE_LOGISTICAL_CTRL,OWNER.FINANCE_LOGISTICAL_CALC_BY,CHECK_THE_WEIGHT_DIFFERENCE,PERCENTAGE_WEIGHT_DIFFERENCE,DIFFERENCES_IN_APPROACH, SAME_WEIGHT_BY_STYLE, IS_ASNREFER_TO_LOT01, ASN_REFER01, ASN_TO_LOT_ATTR01, IS_ASNREFER_TO_LOT02, ASN_REFER02, ASN_TO_LOT_ATTR02, IS_ASNREFER_TO_LOT03, ASN_REFER03, ASN_TO_LOT_ATTR03, IS_ASNREFER_TO_LOT04, ASN_REFER04, ASN_TO_LOT_ATTR04, IS_ASNREFER_TO_LOT05, ASN_REFER05, ASN_TO_LOT_ATTR05  FROM  @_@OWNER OWNER INNER JOIN SYSADM.USER_OWNER UO ON OWNER.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ";
        private string SQL_UPDATE_OWNER = " UPDATE @_@OWNER SET WH_ID = @WH_ID, TYPE = @TYPE, COMPANY = @COMPANY, DESCRIPTION = @DESCRIPTION, VAT = @VAT, CITY = @CITY, STATE = @STATE, ZIP = @ZIP, COUNTRY = @COUNTRY, ADDRESS = @ADDRESS, CONTACT1 = @CONTACT1, CONTACT2 = @CONTACT2, PHONE1 = @PHONE1, PHONE2 = @PHONE2, FAX1 = @FAX1, FAX2 = @FAX2, EMAIL1 = @EMAIL1, EMAIL2 = @EMAIL2, B_CITY = @B_CITY, B_STATE = @B_STATE, B_ZIP = @B_ZIP, B_COUNTRY = @B_COUNTRY, B_COUNTRY_CODE = @B_COUNTRY_CODE, B_ADDRESS = @B_ADDRESS, B_CONTACT1 = @B_CONTACT1, B_CONTACT2 = @B_CONTACT2, B_PHONE1 = @B_PHONE1, B_PHONE2 = @B_PHONE2, B_FAX1 = @B_FAX1, B_FAX2 = @B_FAX2, B_EMAIL1 = @B_EMAIL1, B_EMAIL2 = @B_EMAIL2, UDF1 = @UDF1, UDF2 = @UDF2, UDF3 = @UDF3, UDF4 = @UDF4, UDF5 = @UDF5, UDF6 = @UDF6, UDF7 = @UDF7, UDF8 = @UDF8, UDF9 = @UDF9, UDF10 = @UDF10, REMARK = @REMARK, IS_ACTIVE = @IS_ACTIVE, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE(),IS_REQUIRED_EXTERNAL_ID=@IS_REQUIRED_EXTERNAL_ID,FINANCE_LOGISTICAL_CTRL = @FINANCE_LOGISTICAL_CTRL,FINANCE_LOGISTICAL_CALC_BY = @FINANCE_LOGISTICAL_CALC_BY,CHECK_THE_WEIGHT_DIFFERENCE=@CHECK_THE_WEIGHT_DIFFERENCE,PERCENTAGE_WEIGHT_DIFFERENCE=@PERCENTAGE_WEIGHT_DIFFERENCE,DIFFERENCES_IN_APPROACH=@DIFFERENCES_IN_APPROACH WHERE OWNER_ID = @OWNER_ID  ";
        private string STATE = "@STATE";
        private string TS = "@TS";
        private string TYPE = "@TYPE";
        private string UDF1 = "@UDF1";
        private string UDF10 = "@UDF10";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UDF6 = "@UDF6";
        private string UDF7 = "@UDF7";
        private string UDF8 = "@UDF8";
        private string UDF9 = "@UDF9";
        private string UPDATED_BY = "@UPDATED_BY";
        private string VAT = "@VAT";
        private string WH_ID = "@WH_ID";
        private string ZIP = "@ZIP";

        public bool CheckTradePartnerIDUnique(string tradePartnerID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_OWNER_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckTradePartnerIDUnique(DataBase dataBase, DbTransaction tran, string tradePartnerID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_OWNER_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteTradePartner(List<string> tradePartnerID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < tradePartnerID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteTradePartner(DataBase dataBase, DbTransaction tran, List<string> tradePartnerID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < tradePartnerID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllTradePartner(string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            return DBHelper.ExecuteDataSet(CommandType.Text, sql, paras);
        }

        public DataSet GetAllTradePartner(DataBase dataBase, DbTransaction tran, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql, paras);
        }

        public TradePartnerInfo GetTradePartnerByID(string tradePartnerID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID) + " WHERE OWNER.OWNER_ID = @OWNER_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            TradePartnerInfo tradePartnerInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    tradePartnerInfo = new TradePartnerInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["OWNER_ID"].ToString(), reader["TYPE"].ToString(), reader["COMPANY"].ToString(), reader["DESCRIPTION"].ToString(), reader["VAT"].ToString(), reader["CREDIT_LIMIT"].ToString(), reader["PO_ALPHA_PREFIX"].ToString(), reader["ASN_ALPHA_PREFIX"].ToString(), reader["SO_ALPHA_PREFIX"].ToString(), reader["CITY"].ToString(), reader["STATE"].ToString(), reader["ZIP"].ToString(), reader["COUNTRY"].ToString(), reader["COUNTRY_CODE"].ToString(), reader["ADDRESS"].ToString(), reader["CONTACT1"].ToString(), reader["CONTACT2"].ToString(), reader["PHONE1"].ToString(), reader["PHONE2"].ToString(), reader["FAX1"].ToString(), reader["FAX2"].ToString(), reader["EMAIL1"].ToString(), reader["EMAIL2"].ToString(), reader["B_CITY"].ToString(), reader["B_STATE"].ToString(), reader["B_ZIP"].ToString(), reader["B_COUNTRY"].ToString(), reader["B_COUNTRY_CODE"].ToString(), reader["B_ADDRESS"].ToString(), reader["B_CONTACT1"].ToString(), reader["B_CONTACT2"].ToString(), reader["B_PHONE1"].ToString(), reader["B_PHONE2"].ToString(), reader["B_FAX1"].ToString(), reader["B_FAX2"].ToString(), reader["B_EMAIL1"].ToString(), reader["B_EMAIL2"].ToString(), reader["DEFAULT_CARTON_GROUP"].ToString(), reader["DEFAULT_PACK_ID"].ToString(), reader["DEFAULT_LOT_TEMPLATE_ID"].ToString(), reader["DEFAULT_PUTAWAY_RULE_ID"].ToString(), reader["DEFAULT_PREALLOCATE_RULE_ID"].ToString(), reader["DEFAULT_ALLOCATE_RULE_ID"].ToString(), reader["DEFAULT_ROTATION_RULE_ID"].ToString(), reader["CALCULATE_PUTAWAY_LOCATION"].ToString(), reader["RECEIPT_VALIDATION_ID"].ToString(), reader["DEFAULT_QC_LOC"].ToString(), reader["DEFAULT_QC_LOC_OUT"].ToString(), reader["DEFAULT_RETURNS_LOC"].ToString(), reader["DEFAULT_PACKING_LOCATION"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), reader["PACKING_VALIDATION_TEMPLATE"].ToString(), reader["ENABLE_OPP_XDOCK"].ToString(), reader["OPP_ORDER_STRATEGY_ID"].ToString(), reader["ALLOW_OVER_SHIPMENT"].ToString(), reader["APPORTION_RULE"].ToString(), (reader["ORDER_DATE_START_DAYS"].ToString() != "") ? int.Parse(reader["ORDER_DATE_START_DAYS"].ToString()) : 0, (reader["ORDER_DATE_END_DAYS"].ToString() != "") ? int.Parse(reader["ORDER_DATE_END_DAYS"].ToString()) : 0, (reader["MAXIMUM_ORDERS"].ToString() != "") ? int.Parse(reader["MAXIMUM_ORDERS"].ToString()) : 0, (reader["MINIMUM_PERCENT"].ToString() != "") ? decimal.Parse(reader["MINIMUM_PERCENT"].ToString()) : 0M, reader["ORDER_TYPE_RESTRICT01"].ToString(), reader["ORDER_TYPE_RESTRICT02"].ToString(), reader["ORDER_TYPE_RESTRICT03"].ToString(), reader["ORDER_TYPE_RESTRICT04"].ToString(), reader["ORDER_TYPE_RESTRICT05"].ToString(), reader["ORDER_TYPE_RESTRICT06"].ToString(), reader["ENABLE_PACKING_DEFAULT"].ToString(), reader["INSPECT_AT_PACK"].ToString(), reader["MULTI_ZONE_PL_PA"].ToString(), reader["CREATE_PA_TASK_ON_RF_RECEIPT"].ToString(), reader["ORDER_BREAK_DEFAULT"].ToString(), reader["LPN_BARCODE_SYMBOLOGY"].ToString(), reader["LPN_BARCODE_FORMAT"].ToString(), (reader["LPN_LENGTH"].ToString() != "") ? int.Parse(reader["LPN_LENGTH"].ToString()) : 0, reader["LPN_START_NUMBER"].ToString(), reader["NEXT_LPN_NUMBER"].ToString(), reader["LPN_ROLLBACK_NUMBER"].ToString(), reader["CASE_LABEL_TYPE"].ToString(), reader["APPLICATION_ID"].ToString(), (reader["SSCC_1ST_DIGIT"].ToString() != "") ? int.Parse(reader["SSCC_1ST_DIGIT"].ToString()) : 0, reader["UCC_VENDOR_NUMBER"].ToString(), reader["CC_DISCREPANCY_RULE"].ToString(), reader["CC_ADJ_BY_RF"].ToString(), reader["CC_SKU_LOC"].ToString(), reader["PI_SKU_LOC"].ToString(), reader["ALLOW_COMMINGLED_LPN"].ToString(), reader["ALLOW_AUTO_CLOSE_FOR_ASN"].ToString(), reader["ALLOW_AUTO_CLOSE_FOR_PO"].ToString(), reader["ALLOW_SYSTEM_GENERATED_LPN"].ToString(), reader["ALLOW_SINGLE_SCANRECEIVING"].ToString(), reader["BARCODE_CONFIG_ID"].ToString(), reader["TRACK_INVENTORY_BY"].ToString(), reader["DUP_CASE_ID"].ToString(), reader["SKU_SETUP_REQUIRED"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["IS_REQUIRED_EXTERNAL_ID"].ToString(), reader["FINANCE_LOGISTICAL_CTRL"].ToString(), reader["FINANCE_LOGISTICAL_CALC_BY"].ToString(), reader["CHECK_THE_WEIGHT_DIFFERENCE"].ToString(), (reader["PERCENTAGE_WEIGHT_DIFFERENCE"].ToString() != "") ? Convert.ToDecimal(reader["PERCENTAGE_WEIGHT_DIFFERENCE"]) : 0M, reader["DIFFERENCES_IN_APPROACH"].ToString(), reader["SAME_WEIGHT_BY_STYLE"].ToString(), reader["IS_ASNREFER_TO_LOT01"].ToString(), reader["ASN_REFER01"].ToString(), reader["ASN_TO_LOT_ATTR01"].ToString(), reader["IS_ASNREFER_TO_LOT02"].ToString(), reader["ASN_REFER02"].ToString(), reader["ASN_TO_LOT_ATTR02"].ToString(), reader["IS_ASNREFER_TO_LOT03"].ToString(), reader["ASN_REFER03"].ToString(), reader["ASN_TO_LOT_ATTR03"].ToString(), reader["IS_ASNREFER_TO_LOT04"].ToString(), reader["ASN_REFER04"].ToString(), reader["ASN_TO_LOT_ATTR04"].ToString(), reader["IS_ASNREFER_TO_LOT05"].ToString(), reader["ASN_REFER05"].ToString(), reader["ASN_TO_LOT_ATTR05"].ToString());
                }
            }
            return tradePartnerInfo;
        }

        public TradePartnerInfo GetTradePartnerByID(DataBase dataBase, DbTransaction tran, string tradePartnerID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID) + " WHERE OWNER.OWNER_ID = @OWNER_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            TradePartnerInfo tradePartnerInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                tradePartnerInfo = new TradePartnerInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["OWNER_ID"].ToString(), reader["TYPE"].ToString(), reader["COMPANY"].ToString(), reader["DESCRIPTION"].ToString(), reader["VAT"].ToString(), reader["CREDIT_LIMIT"].ToString(), reader["PO_ALPHA_PREFIX"].ToString(), reader["ASN_ALPHA_PREFIX"].ToString(), reader["SO_ALPHA_PREFIX"].ToString(), reader["CITY"].ToString(), reader["STATE"].ToString(), reader["ZIP"].ToString(), reader["COUNTRY"].ToString(), reader["COUNTRY_CODE"].ToString(), reader["ADDRESS"].ToString(), reader["CONTACT1"].ToString(), reader["CONTACT2"].ToString(), reader["PHONE1"].ToString(), reader["PHONE2"].ToString(), reader["FAX1"].ToString(), reader["FAX2"].ToString(), reader["EMAIL1"].ToString(), reader["EMAIL2"].ToString(), reader["B_CITY"].ToString(), reader["B_STATE"].ToString(), reader["B_ZIP"].ToString(), reader["B_COUNTRY"].ToString(), reader["B_COUNTRY_CODE"].ToString(), reader["B_ADDRESS"].ToString(), reader["B_CONTACT1"].ToString(), reader["B_CONTACT2"].ToString(), reader["B_PHONE1"].ToString(), reader["B_PHONE2"].ToString(), reader["B_FAX1"].ToString(), reader["B_FAX2"].ToString(), reader["B_EMAIL1"].ToString(), reader["B_EMAIL2"].ToString(), reader["DEFAULT_CARTON_GROUP"].ToString(), reader["DEFAULT_PACK_ID"].ToString(), reader["DEFAULT_LOT_TEMPLATE_ID"].ToString(), reader["DEFAULT_PUTAWAY_RULE_ID"].ToString(), reader["DEFAULT_PREALLOCATE_RULE_ID"].ToString(), reader["DEFAULT_ALLOCATE_RULE_ID"].ToString(), reader["DEFAULT_ROTATION_RULE_ID"].ToString(), reader["CALCULATE_PUTAWAY_LOCATION"].ToString(), reader["RECEIPT_VALIDATION_ID"].ToString(), reader["DEFAULT_QC_LOC"].ToString(), reader["DEFAULT_QC_LOC_OUT"].ToString(), reader["DEFAULT_RETURNS_LOC"].ToString(), reader["DEFAULT_PACKING_LOCATION"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), reader["PACKING_VALIDATION_TEMPLATE"].ToString(), reader["ENABLE_OPP_XDOCK"].ToString(), reader["OPP_ORDER_STRATEGY_ID"].ToString(), reader["ALLOW_OVER_SHIPMENT"].ToString(), reader["APPORTION_RULE"].ToString(), (reader["ORDER_DATE_START_DAYS"].ToString() != "") ? int.Parse(reader["ORDER_DATE_START_DAYS"].ToString()) : 0, (reader["ORDER_DATE_END_DAYS"].ToString() != "") ? int.Parse(reader["ORDER_DATE_END_DAYS"].ToString()) : 0, (reader["MAXIMUM_ORDERS"].ToString() != "") ? int.Parse(reader["MAXIMUM_ORDERS"].ToString()) : 0, (reader["MINIMUM_PERCENT"].ToString() != "") ? decimal.Parse(reader["MINIMUM_PERCENT"].ToString()) : 0M, reader["ORDER_TYPE_RESTRICT01"].ToString(), reader["ORDER_TYPE_RESTRICT02"].ToString(), reader["ORDER_TYPE_RESTRICT03"].ToString(), reader["ORDER_TYPE_RESTRICT04"].ToString(), reader["ORDER_TYPE_RESTRICT05"].ToString(), reader["ORDER_TYPE_RESTRICT06"].ToString(), reader["ENABLE_PACKING_DEFAULT"].ToString(), reader["INSPECT_AT_PACK"].ToString(), reader["MULTI_ZONE_PL_PA"].ToString(), reader["CREATE_PA_TASK_ON_RF_RECEIPT"].ToString(), reader["ORDER_BREAK_DEFAULT"].ToString(), reader["LPN_BARCODE_SYMBOLOGY"].ToString(), reader["LPN_BARCODE_FORMAT"].ToString(), (reader["LPN_LENGTH"].ToString() != "") ? int.Parse(reader["LPN_LENGTH"].ToString()) : 0, reader["LPN_START_NUMBER"].ToString(), reader["NEXT_LPN_NUMBER"].ToString(), reader["LPN_ROLLBACK_NUMBER"].ToString(), reader["CASE_LABEL_TYPE"].ToString(), reader["APPLICATION_ID"].ToString(), (reader["SSCC_1ST_DIGIT"].ToString() != "") ? int.Parse(reader["SSCC_1ST_DIGIT"].ToString()) : 0, reader["UCC_VENDOR_NUMBER"].ToString(), reader["CC_DISCREPANCY_RULE"].ToString(), reader["CC_ADJ_BY_RF"].ToString(), reader["CC_SKU_LOC"].ToString(), reader["PI_SKU_LOC"].ToString(), reader["ALLOW_COMMINGLED_LPN"].ToString(), reader["ALLOW_AUTO_CLOSE_FOR_ASN"].ToString(), reader["ALLOW_AUTO_CLOSE_FOR_PO"].ToString(), reader["ALLOW_SYSTEM_GENERATED_LPN"].ToString(), reader["ALLOW_SINGLE_SCANRECEIVING"].ToString(), reader["BARCODE_CONFIG_ID"].ToString(), reader["TRACK_INVENTORY_BY"].ToString(), reader["DUP_CASE_ID"].ToString(), reader["SKU_SETUP_REQUIRED"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["IS_REQUIRED_EXTERNAL_ID"].ToString(), reader["FINANCE_LOGISTICAL_CTRL"].ToString(), reader["FINANCE_LOGISTICAL_CALC_BY"].ToString(), reader["CHECK_THE_WEIGHT_DIFFERENCE"].ToString(), (reader["PERCENTAGE_WEIGHT_DIFFERENCE"].ToString() != "") ? Convert.ToDecimal(reader["PERCENTAGE_WEIGHT_DIFFERENCE"]) : 0M, reader["DIFFERENCES_IN_APPROACH"].ToString(), reader["SAME_WEIGHT_BY_STYLE"].ToString(), reader["IS_ASNREFER_TO_LOT01"].ToString(), reader["ASN_REFER01"].ToString(), reader["ASN_TO_LOT_ATTR01"].ToString(), reader["IS_ASNREFER_TO_LOT02"].ToString(), reader["ASN_REFER02"].ToString(), reader["ASN_TO_LOT_ATTR02"].ToString(), reader["IS_ASNREFER_TO_LOT03"].ToString(), reader["ASN_REFER03"].ToString(), reader["ASN_TO_LOT_ATTR03"].ToString(), reader["IS_ASNREFER_TO_LOT04"].ToString(), reader["ASN_REFER04"].ToString(), reader["ASN_TO_LOT_ATTR04"].ToString(), reader["IS_ASNREFER_TO_LOT05"].ToString(), reader["ASN_REFER05"].ToString(), reader["ASN_TO_LOT_ATTR05"].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return tradePartnerInfo;
        }

        public DataSet GetTradePartnerByQueryList(List<string> sqlWhere, TradePartnerQueryEntity tradePartnerQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!tradePartnerQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, tradePartnerQuery.CurrentPage, tradePartnerQuery.PageSize, tradePartnerQuery.SortField, tradePartnerQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetTradePartnerByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, TradePartnerQueryEntity tradePartnerQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!tradePartnerQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, tradePartnerQuery.CurrentPage, tradePartnerQuery.PageSize, tradePartnerQuery.SortField, tradePartnerQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertTradePartner(TradePartnerInfo tradePartnerInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    tradePartnerInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TradePartner_Parameters(tradePartnerInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertTradePartner(DataBase dataBase, DbTransaction tran, TradePartnerInfo tradePartnerInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    tradePartnerInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TradePartner_Parameters(tradePartnerInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_TradePartner_Parameters(TradePartnerInfo ownerInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.OWNER_ID, SqlDbType.VarChar, 20), new SqlParameter(this.TYPE, SqlDbType.VarChar, 30), new SqlParameter(this.COMPANY, SqlDbType.VarChar, 50), new SqlParameter(this.DESCRIPTION, SqlDbType.VarChar, 50), new SqlParameter(this.VAT, SqlDbType.VarChar, 20), new SqlParameter(this.CITY, SqlDbType.VarChar, 50), new SqlParameter(this.STATE, SqlDbType.VarChar, 20), new SqlParameter(this.ZIP, SqlDbType.VarChar, 20), new SqlParameter(this.COUNTRY, SqlDbType.VarChar, 30), new SqlParameter(this.ADDRESS, SqlDbType.VarChar, 200), new SqlParameter(this.CONTACT1, SqlDbType.VarChar, 30), new SqlParameter(this.CONTACT2, SqlDbType.VarChar, 30), new SqlParameter(this.PHONE1, SqlDbType.VarChar, 20), new SqlParameter(this.PHONE2, SqlDbType.VarChar, 20), new SqlParameter(this.FAX1, SqlDbType.VarChar, 20), 
                new SqlParameter(this.FAX2, SqlDbType.VarChar, 20), new SqlParameter(this.EMAIL1, SqlDbType.VarChar, 60), new SqlParameter(this.EMAIL2, SqlDbType.VarChar, 60), new SqlParameter(this.B_CITY, SqlDbType.VarChar, 50), new SqlParameter(this.B_STATE, SqlDbType.VarChar, 20), new SqlParameter(this.B_ZIP, SqlDbType.VarChar, 20), new SqlParameter(this.B_COUNTRY, SqlDbType.VarChar, 30), new SqlParameter(this.B_COUNTRY_CODE, SqlDbType.VarChar, 20), new SqlParameter(this.B_ADDRESS, SqlDbType.VarChar, 200), new SqlParameter(this.B_CONTACT1, SqlDbType.VarChar, 30), new SqlParameter(this.B_CONTACT2, SqlDbType.VarChar, 30), new SqlParameter(this.B_PHONE1, SqlDbType.VarChar, 20), new SqlParameter(this.B_PHONE2, SqlDbType.VarChar, 20), new SqlParameter(this.B_FAX1, SqlDbType.VarChar, 20), new SqlParameter(this.B_FAX2, SqlDbType.VarChar, 20), new SqlParameter(this.B_EMAIL1, SqlDbType.VarChar, 60), 
                new SqlParameter(this.B_EMAIL2, SqlDbType.VarChar, 60), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.UDF6, SqlDbType.VarChar, 30), new SqlParameter(this.UDF7, SqlDbType.VarChar, 30), new SqlParameter(this.UDF8, SqlDbType.VarChar, 30), new SqlParameter(this.UDF9, SqlDbType.VarChar, 30), new SqlParameter(this.UDF10, SqlDbType.VarChar, 30), new SqlParameter(this.REMARK, SqlDbType.VarChar, 0x7d0), new SqlParameter(this.IS_ACTIVE, SqlDbType.VarChar, 1), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.IS_REQUIRED_EXTERNAL_ID, SqlDbType.VarChar, 1), 
                new SqlParameter(this.FINANCE_LOGISTICAL_CTRL, SqlDbType.VarChar, 1), new SqlParameter(this.FINANCE_LOGISTICAL_CALC_BY, SqlDbType.VarChar, 20), new SqlParameter(this.CHECK_THE_WEIGHT_DIFFERENCE, SqlDbType.VarChar, 1), new SqlParameter(this.PERCENTAGE_WEIGHT_DIFFERENCE, SqlDbType.Decimal, 0x16), new SqlParameter(this.DIFFERENCES_IN_APPROACH, SqlDbType.VarChar, 20)
             };
            if (!string.IsNullOrEmpty(ownerInfo.WhID))
            {
                paramArray[0].Value = ownerInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = ownerInfo.OwnerID;
            if (!string.IsNullOrEmpty(ownerInfo.Type))
            {
                paramArray[2].Value = ownerInfo.Type;
            }
            else
            {
                paramArray[2].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Company))
            {
                paramArray[3].Value = ownerInfo.Company;
            }
            else
            {
                paramArray[3].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Description))
            {
                paramArray[4].Value = ownerInfo.Description;
            }
            else
            {
                paramArray[4].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Vat))
            {
                paramArray[5].Value = ownerInfo.Vat;
            }
            else
            {
                paramArray[5].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.City))
            {
                paramArray[6].Value = ownerInfo.City;
            }
            else
            {
                paramArray[6].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.State))
            {
                paramArray[7].Value = ownerInfo.State;
            }
            else
            {
                paramArray[7].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Zip))
            {
                paramArray[8].Value = ownerInfo.Zip;
            }
            else
            {
                paramArray[8].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Country))
            {
                paramArray[9].Value = ownerInfo.Country;
            }
            else
            {
                paramArray[9].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Address))
            {
                paramArray[10].Value = ownerInfo.Address;
            }
            else
            {
                paramArray[10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Contact1))
            {
                paramArray[11].Value = ownerInfo.Contact1;
            }
            else
            {
                paramArray[11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Contact2))
            {
                paramArray[12].Value = ownerInfo.Contact2;
            }
            else
            {
                paramArray[12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Phone1))
            {
                paramArray[13].Value = ownerInfo.Phone1;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Phone2))
            {
                paramArray[14].Value = ownerInfo.Phone2;
            }
            else
            {
                paramArray[14].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Fax1))
            {
                paramArray[15].Value = ownerInfo.Fax1;
            }
            else
            {
                paramArray[15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Fax2))
            {
                paramArray[0x10].Value = ownerInfo.Fax2;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Email1))
            {
                paramArray[0x11].Value = ownerInfo.Email1;
            }
            else
            {
                paramArray[0x11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Email2))
            {
                paramArray[0x12].Value = ownerInfo.Email2;
            }
            else
            {
                paramArray[0x12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BCity))
            {
                paramArray[0x13].Value = ownerInfo.BCity;
            }
            else
            {
                paramArray[0x13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BState))
            {
                paramArray[20].Value = ownerInfo.BState;
            }
            else
            {
                paramArray[20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BZip))
            {
                paramArray[0x15].Value = ownerInfo.BZip;
            }
            else
            {
                paramArray[0x15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BCountry))
            {
                paramArray[0x16].Value = ownerInfo.BCountry;
            }
            else
            {
                paramArray[0x16].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BCountryCode))
            {
                paramArray[0x17].Value = ownerInfo.BCountryCode;
            }
            else
            {
                paramArray[0x17].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BAddress))
            {
                paramArray[0x18].Value = ownerInfo.BAddress;
            }
            else
            {
                paramArray[0x18].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BContact1))
            {
                paramArray[0x19].Value = ownerInfo.BContact1;
            }
            else
            {
                paramArray[0x19].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BContact2))
            {
                paramArray[0x1a].Value = ownerInfo.BContact2;
            }
            else
            {
                paramArray[0x1a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BPhone1))
            {
                paramArray[0x1b].Value = ownerInfo.BPhone1;
            }
            else
            {
                paramArray[0x1b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BPhone2))
            {
                paramArray[0x1c].Value = ownerInfo.BPhone2;
            }
            else
            {
                paramArray[0x1c].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BFax1))
            {
                paramArray[0x1d].Value = ownerInfo.BFax1;
            }
            else
            {
                paramArray[0x1d].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BFax2))
            {
                paramArray[30].Value = ownerInfo.BFax2;
            }
            else
            {
                paramArray[30].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BEmail1))
            {
                paramArray[0x1f].Value = ownerInfo.BEmail1;
            }
            else
            {
                paramArray[0x1f].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BEmail2))
            {
                paramArray[0x20].Value = ownerInfo.BEmail2;
            }
            else
            {
                paramArray[0x20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf1))
            {
                paramArray[0x21].Value = ownerInfo.Udf1;
            }
            else
            {
                paramArray[0x21].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf2))
            {
                paramArray[0x22].Value = ownerInfo.Udf2;
            }
            else
            {
                paramArray[0x22].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf3))
            {
                paramArray[0x23].Value = ownerInfo.Udf3;
            }
            else
            {
                paramArray[0x23].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf4))
            {
                paramArray[0x24].Value = ownerInfo.Udf4;
            }
            else
            {
                paramArray[0x24].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf5))
            {
                paramArray[0x25].Value = ownerInfo.Udf5;
            }
            else
            {
                paramArray[0x25].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf6))
            {
                paramArray[0x26].Value = ownerInfo.Udf6;
            }
            else
            {
                paramArray[0x26].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf7))
            {
                paramArray[0x27].Value = ownerInfo.Udf7;
            }
            else
            {
                paramArray[0x27].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf8))
            {
                paramArray[40].Value = ownerInfo.Udf8;
            }
            else
            {
                paramArray[40].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf9))
            {
                paramArray[0x29].Value = ownerInfo.Udf9;
            }
            else
            {
                paramArray[0x29].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf10))
            {
                paramArray[0x2a].Value = ownerInfo.Udf10;
            }
            else
            {
                paramArray[0x2a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Remark))
            {
                paramArray[0x2b].Value = ownerInfo.Remark;
            }
            else
            {
                paramArray[0x2b].Value = DBNull.Value;
            }
            paramArray[0x2c].Value = ownerInfo.IsActive;
            paramArray[0x2d].Value = ownerInfo.CreatedBy;
            paramArray[0x2e].Value = ownerInfo.UpdatedBy;
            paramArray[0x2f].Value = ownerInfo.IsRequiredExternalID;
            paramArray[0x30].Value = ownerInfo.Finance_Logistical_Ctrl;
            if (!string.IsNullOrEmpty(ownerInfo.Finance_Logistical_Calc_By))
            {
                paramArray[0x31].Value = ownerInfo.Finance_Logistical_Calc_By;
            }
            else
            {
                paramArray[0x31].Value = DBNull.Value;
            }
            paramArray[50].Value = ownerInfo.CheckTheWeightDifference;
            paramArray[0x33].Value = ownerInfo.PercentageWeightDifference;
            paramArray[0x34].Value = ownerInfo.DifferencesInApproach;
            return paramArray;
        }

        public int UpdateTradePartner(TradePartnerInfo tradePartnerInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    tradePartnerInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TradePartner_Parameters(tradePartnerInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateTradePartner(DataBase dataBase, DbTransaction tran, TradePartnerInfo tradePartnerInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    tradePartnerInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TradePartner_Parameters(tradePartnerInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

